import { goodsadd, goodscount, goodsdelete, goodsedit, goodsinfo, goodslist } from "../../utils/request/api.js";
export default {
    goodslist_a( { commit }, payload) {
        goodslist(payload).then(res => {
            if (res.code == 200 && res.list) {
                 commit('setgoodslist',res.list)
            }
        })
    },
    goodscount_a({ commit }) {
        goodscount().then(res => {
            commit('setgoodscount',res.list[0])
        })
    },
    goodsadd_a({ commit }, payload) {
        goodsadd(payload).then(res => {
             commit('setgoodsTitle', res)
        })
    },
    goodsdelete_a({ commit }, payload) {
        goodsdelete(payload).then(res => {
            //把操作成功变成删除成功
            if (res.code == 200) {
                commit('setgoodsTitle', {...res,msg:"删除成功"})
            }
        })
    },
    goodsinfo_a({ commit }, payload) {
        goodsinfo(payload).then(res => {
            //点击编辑的时候 直接把id添加到goodsinfo上 把specsattr变成数组形式
            commit('setgoodsinfo', { ...res.list, id: payload, specsattr: res.list.specsattr.split(',') })
        })
    },
    goodsedit_a({ commit }, payload) {
        goodsedit(payload).then(res => {
            //把操作成功变成修改成功
            commit('setgoodsTitle',{...res,msg:"修改成功"})
        })
    },
}